<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <head th:replace="common/head"/>
</head>
<body>
<div class="x-body">
    <form class="layui-form layui-form-pane" action="/purchaseGoods/doAdd">
        <input type="hidden" id="purchaseBaseId" name="purchaseBaseId" th:value="${purchaseBaseId}">

        <div class="layui-inline" style="margin-bottom: 15px">
            <label class="layui-form-label">商品</label>
            <div class="layui-input-inline" style="width: 300px">
                <select name="goodsId" lay-verify="required" lay-search="" lay-filter="doSelect">
                    <option value="">直接选择或搜索选择</option>
                    <th:block th:each="map: ${goodsList}">
                        <option th:value="${map.goodsId}" th:text="${map.goodsCode+'/'+map.goodsName}"></option>
                    </th:block>
                </select>
            </div>
        </div>
        <p id="goodsDetail" style="color: red;margin-bottom: 10px"></p>

        <div class="layui-form-item">
            <label class="layui-form-label">进货量</label>
            <div class="layui-input-block" style="width: 300px">
                <input type="text" name="goodsCount" lay-verify="required|checkDec" placeholder="必填,正数" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">进货价</label>
            <div class="layui-input-block" style="width: 300px">
                <input type="text" name="goodsPurchaseMoney" lay-verify="required|checkDec" placeholder="必填,正数" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" style="margin-left:200px;" lay-submit lay-filter="submit">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<div th:replace="common/js"></div>
<div th:replace="common/setting"></div>
<script type="text/javascript">
    layui.use('xlayform');
    layui.use(['layer', 'form'], function(){
        var $ = layui.jquery,
            form = layui.form;
        form.on('select(doSelect)', function(data){
            $.get('/goods/selectById', {goodsId:data.value}, function (result) {
                if (result.code == 0) {
                    $("#goodsDetail").html("&nbsp;&nbsp;零售价："+result.data.retailPrice+"&nbsp;&nbsp;批发价："+result.data.wholesalePrice);
                } else {
                    layer.msg(result.msg, {
                        icon: 2,
                        time: 5000
                    });
                    $("#goodsDetail").html("");
                }
            });
            return null;
        });
    });

</script>
</body>
</html>
